<?php
session_start();
ob_start("ob_gzhandler");
require_once '../models/Customer.php';

	if(isset($_POST["email"])){
		$_msg="";
		$check=true;
		$email=$_POST["email"];
		$password=$_POST["password"];
		$encryptpassword=Customer::encryptpassword($password);
		$row=Customer::checkCustomerLogin($email,$encryptpassword);
		$_SESSION["session_customer_id"]=$row['customerID'];
		$_SESSION["session_customer_email"]=$email;
		$_SESSION["session_customer_status"]=$row['status'];
		$session_customer_status=$row['status'];
		$_SESSION["session_customer_password"]=$encryptpassword;	
		$session_customer_id=$row['customerID'];
		if($session_customer_id>0 ){
			if($session_customer_status==USER_VALUE_ACTIVE){
				header("location: index.php");
				}
			else{
				$_msg.="Tài khoản của bạn chưa được kích hoạt!";
				$check=false;
			}
		}
		else{
		$_msg.="Đăng nhập thất bại!";
		$check=false;
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
<title>Đăng nhập</title>
<?php include '_meta.php';?>
</head>
<body>
	<div id="firstLine">
		<div id="top-bar">
		<?php include '_top_bar.php';?>
		</div>
	</div>
	<div id="container">
		<div id="header">
			<?php include '_head.php';?>
		</div>
		<?php include '_menu_head.php';?>
		<div id="center">
			<div id="menu-left">
				<?php include '_menu_left.php';?>
			</div>
			<div id="table">
				<form name="myForm" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
				<div id="div_login">
				<div id="content_login">
					<div id="head_login">
						<div class="lbl_"><h2>Đăng Nhập</h2></div>
						<div id="border-bottom_w317_h2"<div>
					</div>
					<div id="article_login">
						<div>
							<input type="email" id="email" name="email" class="input_text_w200_h30" placeholder="Nhập tên Email" />
						</div>
						<div>
							<input type="password" id="password" name="password" class="input_text_w200_h30" placeholder="Nhập mật khẩu"/>
						</div>
						<div id="btn_dn">
							<input type="submit" class="btn_button_" name="btn_submit" value="Đăng Nhập" >
							<a href="index.php"><input type="button" class="btn_button_" value="Quay lại trang chủ"></a>
						</div>
						<div>
							<?php 
							if(isset($_POST['btn_submit'])){
								if($check==false){
									echo $_msg;
								}
							}
							?>
						</div>
					</div>
				</div>
				</div>
				</form>
			</div>
			<div id="menu-left">
				<?php //include '_menu_left.php';?>
			</div>
			</div>
		</div>
	</div>
	<div id="footer">
		<?php include '_footer.php';?>
	</div>
</body>
</html>